package entidades.DAOs;

import java.sql.Date;
import java.sql.SQLException;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.Time;

import utilidades.ConexionBD;
import entidades.Accion;
import entidades.Auditoria;

public class DAOauditorias {
	
	public static Accion setAccion(int id_accion) throws SQLException, ClassNotFoundException{
		
		ConexionBD.conectar();
		Statement sql = ConexionBD.conexion.createStatement();
		ResultSet rsAccion = sql.executeQuery("SELECT * FROM accion WHERE id_accion = "+id_accion+";");
		rsAccion.first();
		Accion auxAccion = new Accion();
		auxAccion.setId_accion(id_accion);
		auxAccion.setTipo(rsAccion.getString("tipo"));
		
		return auxAccion;
		
	}

	public static void guardar(Auditoria aud)throws SQLException, ClassNotFoundException {
		// TODO Auto-generated method stub
		ConexionBD.conectar();
        Statement sentencia=ConexionBD.conexion.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
        sentencia.execute("INSERT INTO auditoria"+"(id_auditoria,hora,fecha,id_accion,id_usuario)"+
        								 "VALUES ("+Integer.toString(aud.getId_aud())+","+"'"+(Time)aud.getHora()+"'"+","+"'"+(Date)aud.getDia()+"'"+","+
        		Integer.toString(aud.getM_Accion().getId_accion())+","+Integer.toString(aud.getId_usuario())+");");
         
        ConexionBD.desconectar();
	}
	
}
